<template>
  <div class="ai-main-layout">
    <div class="ai-left">
      <div class="qa-history-section">
        <h3>历史问答</h3>
        <ul class="qa-history-list">
          <li v-for="(item, idx) in qaList" :key="idx">Q: {{ item.q }}<br/>A: {{ item.a }}</li>
          <li v-if="qaList.length === 0" class="empty">暂无历史问答</li>
        </ul>
      </div>
      <div class="ai-helper-section">
        <h4>使用说明</h4>
        <ul class="ai-helper-list">
          <li>可提问学习、生活、技术等问题。</li>
          <li>深度思考：更详细、逻辑更强的回答。</li>
          <li>联网搜索：获取最新网络信息。</li>
        </ul>
      </div>
    </div>
    <div class="ai-right">
      <div class="ai-chat-card">
        <h2>AI智能问答</h2>
        <div class="ai-btn-group">
          <button :class="['ai-mode-btn', { active: mode.includes('think') } ]" @click="toggleMode('think')">深度思考</button>
          <button :class="['ai-mode-btn', { active: mode.includes('search') } ]" @click="toggleMode('search')">联网搜索</button>
        </div>
        <form class="qa-form" @submit.prevent="ask">
          <textarea v-model="question" placeholder="请输入你的问题..." class="ai-textarea"></textarea>
          <button type="submit" class="primary-btn">发送</button>
        </form>
        <div v-if="answer" class="ai-answer">
          <strong>AI：</strong>{{ answer }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import '@/assets/styles/common.css'

const question = ref('')
const answer = ref('')
const mode = ref([])
const qaList = ref([
  { q: '校园平台能做什么？', a: '可以查公告、二手交易、论坛交流等。' },
  { q: '怎么找回密码？', a: '在登录页点击"忘记密码"即可找回。' },
])

function toggleMode(type) {
  if (mode.value.includes(type)) {
    mode.value = mode.value.filter(m => m !== type)
  } else {
    mode.value.push(type)
  }
}

function ask() {
  if (!question.value.trim()) return
  let ans = ''
  if (mode.value.includes('think') && mode.value.includes('search')) {
    ans = '这是深度思考+联网搜索模式下的AI回答。'
  } else if (mode.value.includes('think')) {
    ans = '这是深度思考模式下的AI回答。'
  } else if (mode.value.includes('search')) {
    ans = '这是联网搜索模式下的AI回答。'
  } else {
    ans = '这是普通模式下的AI回答。'
  }
  answer.value = ans
  qaList.value.unshift({ q: question.value, a: answer.value })
  question.value = ''
}
</script>

<style scoped>
.ai-main-layout {
  display: flex;
  gap: 36px;
  max-width: 1100px;
  margin: 40px auto;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 4px 32px rgba(37, 99, 235, 0.10);
  padding: 40px 32px;
}
.ai-left {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-right: 1.5px solid #e5e7eb;
  padding-right: 32px;
}
.qa-history-section {
  background: #f7faff;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(37,99,235,0.06);
  padding: 18px 16px 16px 16px;
}
.qa-history-section h3 {
  color: #2563eb;
  font-size: 1.1em;
  margin-bottom: 8px;
}
.qa-history-list {
  padding-left: 18px;
  color: #555;
  font-size: 0.98em;
  margin: 0;
}
.empty {
  color: #aaa;
  margin: 8px 0;
}
.ai-helper-section {
  background: #f1f5ff;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(37,99,235,0.06);
  padding: 18px 16px 16px 16px;
}
.ai-helper-section h4 {
  color: #2563eb;
  font-size: 1em;
  margin-bottom: 6px;
}
.ai-helper-list {
  padding-left: 18px;
  color: #555;
  font-size: 0.98em;
  margin: 0;
}
.ai-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ai-chat-card {
  width: 100%;
  max-width: 480px;
  background: #f7faff;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(37,99,235,0.06);
  padding: 32px 28px 24px 28px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.ai-btn-group {
  display: flex;
  gap: 16px;
  margin-bottom: 18px;
}
.ai-mode-btn {
  flex: 1;
  background: #fff;
  color: #2563eb;
  border: 1.5px solid #2563eb;
  border-radius: 6px;
  padding: 8px 0;
  font-size: 1em;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.ai-mode-btn.active {
  background: #2563eb;
  color: #fff;
}
.qa-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.ai-textarea {
  min-height: 60px;
  resize: vertical;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  width: 100%;
  font-size: 1.08em;
}
button.primary-btn {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 0;
  font-size: 1.1em;
  font-weight: bold;
  cursor: pointer;
  margin-top: 10px;
}
button.primary-btn:hover {
  background: #1e40af;
}
.ai-answer {
  margin-top: 18px;
  background: #e0e7ff;
  border-radius: 8px;
  padding: 12px 14px;
  color: #222;
  font-size: 1em;
}
@media (max-width: 900px) {
  .ai-main-layout {
    flex-direction: column;
    padding: 24px 8px;
  }
  .ai-left {
    width: 100%;
    border-right: none;
    border-bottom: 1.5px solid #e5e7eb;
    padding-right: 0;
    padding-bottom: 18px;
    margin-bottom: 18px;
  }
  .ai-right {
    align-items: stretch;
    justify-content: flex-start;
  }
}
</style>